<?php

include(dirname(__FILE__).'/../../bootstrap/functional.php');

$browser = new sfTestFunctional(new sfBrowser());

$browser->info('0 - Login')->
  get('/')->
  click('Ok', array('signin' => array(
    'email'         => 'kristina.chung@company.com',
    'password'      => 'password',
  )))->
  with('response')->begin()->
    isStatusCode(302)->
  end()
;

$browser->info('1 - Get users list')->
  get('/users/index')->
  with('request')->begin()->
    isParameter('module', 'users')->
    isParameter('action', 'index')->
  end()->
  with('response')->begin()->
    isStatusCode(200)->
    checkElement('h2', '/Liste des utilisateurs/')->
  end()
;

$browser->info('2 - Add new user')->
  get('/users/new')->
  with('request')->begin()->
    isParameter('module', 'users')->
    isParameter('action', 'new')->
  end()->
  click('input[type=submit]', array('user' => array(
    'fullName'   => 'John DOE',
    'email'      => 'john.doe@company.com',
    'admin'      => true,
    'active'     => true,
    'typeId'     => 1,
  )))->
  with('request')->begin()->
    isParameter('module', 'users')->
    isParameter('action', 'create')->
  end()->
  with('response')->isRedirected()->followRedirect()
;

$browser->info('2 - Edit created user')->
  with('request')->begin()->
    isParameter('module', 'users')->
    isParameter('action', 'edit')->
  end()->
  click('input[type=submit]', array('user' => array(
    'fullName'   => 'Jane DOE',
    'email'      => 'jane.doe@company.com',
    'admin'      => true,
    'active'     => true,
    'typeId'     => 1,
  )))->
  with('request')->begin()->
    isParameter('module', 'users')->
    isParameter('action', 'update')->
  end()->
  with('response')->isRedirected()->followRedirect()->begin()->
    checkElement('.flashes .error', false)->
  end()
;

$browser->info('3 - Delete created user')->
  with('request')->begin()->
    isParameter('module', 'users')->
    isParameter('action', 'edit')->
  end()->
  click('form a', array(), array('method' => 'delete', '_with_csrf' => true))->
  with('request')->begin()->
    isParameter('module', 'users')->
    isParameter('action', 'delete')->
  end()->
  with('response')->isRedirected()->followRedirect()->begin()->
    checkElement('.flashes .error', false)->
  end()
;